<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>书中代码 - 跟着LLM学Python</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            line-height: 1.6;
            background: #f5f5f5;
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 40px;
        }

        .code-section {
            background: white;
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        .code-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .code-block {
            background: #282c34;
            color: #abb2bf;
            padding: 20px;
            border-radius: 8px;
            overflow-x: auto;
        }

        pre {
            margin: 0;
        }

        .copy-btn {
            background: #3498db;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 6px;
            cursor: pointer;
            transition: 0.3s;
        }

        .copy-btn:hover {
            background: #2980b9;
        }

        .back-btn {
            display: inline-block;
            margin-bottom: 20px;
            color: #3498db;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <a href="index.html" class="back-btn">← 返回主页</a>
        <div class="header">
            <h1>书中代码示例</h1>
            <p>所有章节的代码示例汇总</p>
        </div>
        <div class="code-section">
            <div class="code-header">
                <h3>行星轨道模拟</h3>
                <button class="copy-btn">复制代码</button>
            </div>
            <div class="code-block">
                <pre><code>import turtle
import math

def setup_screen():
    screen = turtle.Screen()
    screen.bgcolor("black")
    screen.title("行星运动模拟")
    return screen

def create_planet():
    planet = turtle.Turtle()
    planet.shape("circle")
    planet.color("blue")
    return planet

# 主程序
screen = setup_screen()
planet = create_planet()
# 运动模拟代码...</code></pre>
            </div>
        </div>
        <!-- 添加更多代码示例 -->
    </div>
    <script>
        document.querySelectorAll('.copy-btn').forEach(button => {
            button.addEventListener('click', () => {
                const content = button.parentElement.nextElementSibling.querySelector('code').textContent;
                navigator.clipboard.writeText(content);
                button.textContent = '已复制！';
                setTimeout(() => {
                    button.textContent = '复制代码';
                }, 2000);
            });
        });
    </script>
</body>
</html>